package com.chance.cc.crawler.development.bootstrap.toutiao;

import com.chance.cc.crawler.core.downloader.Downloader;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.core.downloader.HttpRequest;
import com.chance.cc.crawler.core.downloader.http.HttpClientDownloader;
import com.chance.cc.crawler.core.downloader.http.HttpClientGenerator;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.downloader.proxy.SiteConfigProxyProvider;

/**
 * @author lt
 * @version 1.0
 * @date 2021-07-15 14:16:42
 * @email okprog@sina.com
 */
public class TTTest {
    private static Proxy proxy = new Proxy();
    static {
        //代理配置
        //HL89Q19E86E2987D
        //71F33D94CE5F7BF2
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");
    }

    public static void main(String[] args) {
        HttpConfig httpConfig = HttpConfig.me("test");
//        httpConfig.setProxy(proxy);
//        httpConfig.setUseProxy(true);

        HttpClientDownloader downloader = new HttpClientDownloader();
        downloader.setClientGenerator(new HttpClientGenerator());
        downloader.setProxyProvider(new SiteConfigProxyProvider());

        for (int i = 0; i < 10; i++) {
            new Thread(new DownloadTest(httpConfig,downloader),"thread-" + i).start();
        }
    }
    static class DownloadTest implements Runnable{

        HttpConfig httpConfig;
        Downloader downloader;

        public DownloadTest(HttpConfig httpConfig, Downloader downloader) {
            this.httpConfig = httpConfig;
            this.downloader = downloader;
        }

        @Override
        public void run() {
            String url = "https://so.toutiao.com/search?keyword=nike&pd=information&source=search_subtab_switch&dvpf=pc&aid=4916&page_num=0";
            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setUrl(url);
//            httpRequest.addHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
            while (true){
                System.out.println(url);
                try {
                    HttpPage httpPage = downloader.download(httpRequest, httpConfig);
                    System.out.println(httpPage.getRawText());
                } catch (Exception e) {
                    break;
                }
            }
        }
    }

    class t2 extends TTTest{
        
    }
}
